<?php
    class AdminDthink_Form_ValidateUser
    {
        public function validEmail($email) {
            $validator = new Zend_Validate_StringLength(1, 100);
            if($validator->isValid($email)) {
                $validator = new Zend_Validate_EmailAddress();
                if($validator->isValid($email)) {
                    return true;
                }
                else {
                    return false;
                }
            }
            else {
                return false;
            }
        }

        public function validFullname($fullname) {
            $validator = new Zend_Validate_StringLength(1, 100);
            if($validator->isValid($fullname)) {
                $validator = new Zend_Validate_Alpha(true);
                if($validator->isValid($fullname)) {
                    return true;
                }
                else {
                    return false;
                }
            }
            else {
                return false;
            }
        }

        public function validPassword($password) {
            $validator = new Zend_Validate_StringLength(6, 32);
            if($validator->isValid($password)) {
                return true;
            }
            else {
                return false;
            }
        }

        public function validAvatar($avatar) {
            $validator = new Zend_Validate_NotEmpty();
            if($validator->isValid($avatar)) {
                return true;
            }
            else {
                return false;
            }
        }
        
        public function validAddress($address) {
            $validator = new Zend_Validate_StringLength(0, 500);
            if($validator->isValid($address)) {
                return true;
            }
            else {
                return false;
            }
        }
        
        public function validPhone($phone) {
            $validator = new Zend_Validate_StringLength(8, 20);
            if($validator->isValid($phone)) {
                $flag = 0;
                for($i = 0; $i < strlen($phone); $i++) {
                    if(!is_numeric($phone[$i])) {
                        $flag++;
                    }
                }
                if($flag == 0) {
                    return true;
                }
                else {
                    return false;
                }
            }
            else {
                return false;
            }
        }

        public function validSearch($keyword) {
            $validator = new Zend_Validate_StringLength(3, 50);
            if($validator->isValid($keyword)) {
                return true;
            }
            else {
                return false;
            }
        }
    }